<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文档处理工具 - Word去除页眉页脚</title>
    <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    
    <!-- 预加载关键资源 -->
    <link rel="preload" href="/" as="document">
    <link rel="prefetch" href="/">
    
    <style>
        :root {
            --primary-color: #3498db;
            --primary-dark: #2980b9;
            --secondary-color: #2ecc71;
            --secondary-dark: #27ae60;
            --text-color: #333;
            --light-gray: #f5f5f5;
            --medium-gray: #e0e0e0;
            --dark-gray: #777;
            --white: #ffffff;
            --shadow: 0 4px 15px rgba(0,0,0,0.1);
            --border-radius: 8px;
            --transition: all 0.3s ease;
        }
        
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Noto Sans SC', 'Microsoft YaHei', sans-serif;
            line-height: 1.5;
            color: var(--text-color);
            background-color: var(--light-gray);
            display: flex;
            flex-direction: column;
            min-height: 100vh;
            font-size: 0.95rem;
        }
        
        .container {
            max-width: 900px;
            width: 90%;
            margin: 40px auto;
            background-color: var(--white);
            padding: 40px;
            border-radius: var(--border-radius);
            box-shadow: var(--shadow);
            animation: fadeIn 0.8s ease;
        }
        
        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(10px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        h1 {
            color: var(--primary-color);
            text-align: center;
            margin-bottom: 25px;
            font-weight: 700;
            font-size: 1.9rem;
            position: relative;
            padding-bottom: 12px;
        }
        
        h1::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 50%;
            transform: translateX(-50%);
            width: 100px;
            height: 4px;
            background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
            border-radius: 2px;
        }
        
        /* 导航菜单样式 */
        .nav-menu {
            display: flex;
            justify-content: center;
            margin-bottom: 30px;
            background-color: var(--light-gray);
            border-radius: var(--border-radius);
            padding: 5px;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
        }
        
        .nav-menu a {
            text-decoration: none;
            color: var(--text-color);
            padding: 10px 20px;
            border-radius: var(--border-radius);
            margin: 0 5px;
            transition: all 0.1s ease;
            font-weight: 500;
            position: relative;
            overflow: hidden;
        }
        
        .nav-menu a::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: var(--primary-color);
            border-radius: var(--border-radius);
            z-index: -1;
            transform: translateY(100%);
            transition: transform 0.1s ease;
        }
        
        .nav-menu a:hover {
            color: var(--white);
        }
        
        .nav-menu a:hover::before {
            transform: translateY(0);
        }
        
        .nav-menu a.active {
            background-color: var(--primary-color);
            color: white;
        }
        
        .nav-menu a i {
            margin-right: 8px;
        }
        
        .upload-form {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 25px;
            margin: 40px 0;
        }
        
        .file-input-container {
            position: relative;
            width: 100%;
            max-width: 500px;
        }
        
        .file-input-container input[type="file"] {
            position: absolute;
            top: 0;
            left: 0;
            opacity: 0;
            width: 100%;
            height: 100%;
            cursor: pointer;
            z-index: 2;
        }
        
        .file-input-label {
            display: flex;
            align-items: center;
            justify-content: center;
            height: 55px;
            background-color: var(--light-gray);
            border: 2px dashed var(--primary-color);
            border-radius: var(--border-radius);
            text-align: center;
            padding: 12px;
            transition: var(--transition);
            color: var(--text-color);
            font-weight: 500;
            font-size: 0.95rem;
        }
        
        .file-input-label i {
            margin-right: 8px;
            font-size: 1.3rem;
            color: var(--primary-color);
        }
        
        .file-input-label:hover {
            background-color: var(--medium-gray);
            transform: translateY(-2px);
            box-shadow: var(--shadow);
        }
        
        button {
            background: linear-gradient(to right, var(--secondary-color), var(--secondary-dark));
            color: white;
            border: none;
            padding: 12px 25px;
            border-radius: var(--border-radius);
            cursor: pointer;
            font-size: 0.95rem;
            font-weight: 500;
            letter-spacing: 0.5px;
            transition: var(--transition);
            display: inline-flex;
            align-items: center;
            justify-content: center;
            min-width: 160px;
            text-transform: uppercase;
        }
        
        button i {
            margin-right: 8px;
        }
        
        button:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 15px rgba(39, 174, 96, 0.3);
        }
        
        button:active {
            transform: translateY(0);
        }
        
        .alert {
            padding: 15px 20px;
            border-radius: var(--border-radius);
            margin-bottom: 25px;
            text-align: center;
            font-weight: 500;
            animation: slideDown 0.5s ease;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            width: 100%;
            max-width: 700px;
            margin-left: auto;
            margin-right: auto;
        }
        
        @keyframes slideDown {
            from {
                opacity: 0;
                transform: translateY(-20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .alert-danger {
            background-color: #fff2f2;
            color: #e74c3c;
            border-left: 4px solid #e74c3c;
        }
        
        .alert-success {
            background-color: #f0fff4;
            color: var(--secondary-dark);
            border-left: 4px solid var(--secondary-color);
        }
        
        .file-info {
            font-size: 0.9rem;
            color: #6c757d;
            margin-top: 10px;
        }
        
        .progress {
            display: none;
            margin-top: 20px;
            height: 8px;
            background-color: var(--light-gray);
            border-radius: 4px;
            overflow: hidden;
        }
        
        .progress-bar {
            height: 100%;
            background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
            transition: width 0.3s ease;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>文档处理工具</h1>
        
        <!-- 导航菜单 -->
        <div class="nav-menu">
            <a href="/" id="pdfTab"><i class="fas fa-file-pdf"></i>PDF处理</a>
            <a href="/word" class="active"><i class="fas fa-file-word"></i>Word处理</a>
        </div>
        
        <div th:if="${message}" class="alert" th:classappend="${message.contains('成功') ? 'alert-success' : 'alert-danger'}" th:text="${message}"></div>
        
        <div class="feature-description">
            <h2>Word处理功能</h2>
            <p>去除Word文档中的页眉页脚，只保留页码。适用于清理Word文档中的多余信息。</p>
        </div>
        
        <form method="POST" enctype="multipart/form-data" th:action="@{/word/upload}" id="uploadForm" class="upload-form">
            <div class="file-input-container">
                <input type="file" id="file" name="file" class="file-input" accept=".doc,.docx" required />
                <label for="file" class="file-input-label">
                    <i class="fas fa-file-upload"></i>
                    <span id="file-name">选择Word文件或拖放到这里</span>
                </label>
            </div>
            
            <div id="fileInfo" class="file-info"></div>
            
            <div class="progress">
                <div class="progress-bar" role="progressbar" style="width: 0%" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
            </div>
            
            <button type="submit" id="uploadButton" disabled>
                <i class="fas fa-cog"></i>
                处理文件
            </button>
        </form>
        
        <div class="information-section">
            <h3><i class="fas fa-info-circle"></i> 使用说明</h3>
            <ul>
                <li>上传Word文档(.doc或.docx格式), 最大100MB</li>
                <li>系统会自动移除所有页眉内容</li>
                <li>页脚内容会被移除，但保留页码</li>
                <li>处理后可下载文档</li>
            </ul>
        </div>
    </div>
    
    <script>
        document.addEventListener("DOMContentLoaded", function() {
            // 获取元素引用
            const fileInput = document.getElementById('file');
            const fileNameSpan = document.getElementById('file-name');
            const fileInfo = document.getElementById('fileInfo');
            const uploadButton = document.getElementById('uploadButton');
            const form = document.getElementById('uploadForm');
            const progressBar = document.querySelector('.progress');
            const progressBarInner = document.querySelector('.progress-bar');
            
            // 文件选择处理
            fileInput.addEventListener('change', function() {
                if (this.files && this.files[0]) {
                    fileNameSpan.textContent = this.files[0].name;
                    
                    const fileSize = (this.files[0].size / 1024 / 1024).toFixed(2); // MB
                    fileInfo.textContent = `文件名: ${this.files[0].name} | 大小: ${fileSize} MB`;
                    
                    // 检查文件类型和大小限制
                    if (!(this.files[0].name.endsWith('.doc') || this.files[0].name.endsWith('.docx'))) {
                        fileInfo.innerHTML += "<br><span style='color: #e74c3c;'>警告: 不支持的文件类型，请上传Word文档 (.doc或.docx)</span>";
                        uploadButton.setAttribute('disabled', '');
                    } else if (this.files[0].size > 100 * 1024 * 1024) { // 100MB
                        fileInfo.innerHTML += "<br><span style='color: #e74c3c;'>警告: 文件大小超过限制 (最大100MB)</span>";
                        uploadButton.setAttribute('disabled', '');
                    } else {
                        uploadButton.removeAttribute('disabled');
                    }
                } else {
                    fileNameSpan.textContent = '选择Word文件或拖放到这里';
                    fileInfo.textContent = '';
                    uploadButton.setAttribute('disabled', '');
                }
            });
            
            // 拖放功能
            const dropZone = document.querySelector('.file-input-label');
            
            ['dragover', 'dragenter'].forEach(eventName => {
                dropZone.addEventListener(eventName, function(e) {
                    e.preventDefault();
                    dropZone.style.borderColor = "#2ecc71";
                    dropZone.style.backgroundColor = "#f0fff4";
                }, false);
            });
            
            ['dragleave', 'dragend', 'drop'].forEach(eventName => {
                dropZone.addEventListener(eventName, function(e) {
                    e.preventDefault();
                    dropZone.style.borderColor = "#3498db";
                    dropZone.style.backgroundColor = "#f5f5f5";
                }, false);
            });
            
            dropZone.addEventListener('drop', function(e) {
                fileInput.files = e.dataTransfer.files;
                
                // 触发change事件
                const event = new Event('change');
                fileInput.dispatchEvent(event);
            }, false);
            
            // 提交表单时显示进度条
            form.addEventListener('submit', function() {
                progressBar.style.display = 'block';
                uploadButton.setAttribute('disabled', '');
                uploadButton.innerHTML = '<i class="fas fa-spinner fa-spin"></i> 处理中...';
                
                // 模拟进度
                let progress = 0;
                const interval = setInterval(() => {
                    progress += 5;
                    if (progress > 90) {
                        clearInterval(interval);
                    }
                    progressBarInner.style.width = progress + "%";
                    progressBarInner.setAttribute("aria-valuenow", progress);
                }, 300);
            });
            
            // 页签快速切换优化
            const pdfTab = document.getElementById('pdfTab');
            if (pdfTab) {
                pdfTab.addEventListener('mouseenter', function() {
                    const link = document.createElement('link');
                    link.rel = 'prefetch';
                    link.href = '/';
                    document.head.appendChild(link);
                });
                
                pdfTab.addEventListener('click', function(e) {
                    e.preventDefault();
                    pdfTab.classList.add('active');
                    document.body.style.opacity = '0.8';
                    setTimeout(function() {
                        window.location.href = pdfTab.href;
                    }, 10);
                });
            }
        });
    </script>
</body>
</html> 